<?php
echo $this->Html->addCrumb('Batches', '/admin/batches/index');
echo $this->Html->addCrumb('Parts', '/admin/parts/index/'.$part['Part']['batch_id']);
echo $this->Html->addCrumb('Questions', '/admin/questions/index/'.$this->data['Question']['part_id']);
echo $this->Html->addCrumb($this->data['Question']['question']);

eval('$this->data[\'Question\'][\'options\'] =  '.$this->data['Question']['options'].';');

?>
<div class="questions form">
<?php echo $this->Form->create('Question');?>
	<fieldset>
		<legend><?php __('Admin Edit Question'); ?></legend>
	<?php
		echo $this->Form->input('id');
		echo $this->Form->input('part_id');
		echo $this->Form->input('question');
		echo $this->Form->input('type',array('type'=>'hidden','value'=>''));
	?>
		<span id="TextBoxesGroup">
	<?php
		if(is_array($this->data['Question']['options']))
		{
			$i = 1;
			?>
			<script>
			var counter = <?=count($this->data['Question']['options'])?>;
			</script>
			<?php
			foreach($this->data['Question']['options'] as $ques)
			{
				?>
				<div id="tb<?=$i++?>"><span>Option 1</span><input type="text" id="QuestionOptions" name="data[Question][options][]" value="<?=$ques?>"></div>
				<?php
			}
		}
		else
		{
			?>
			<script>
			var counter = 0;
			</script>
			<input type="hidden" id="QuestionOptions" name="data[Question][options][]" value="<?=$ques?>">
			<?php
		}
	?>
		</span>	
		<input type="button" id="addButton" value="Add Option" style="font-size:100%;padding:0px;width:auto;" />
		<input type="button" id="removeButton" value="Remove Option" style="font-size:100%;padding:0px;width:auto;" />
	<?php
//		echo $this->Form->input('options');
		echo $this->Form->input('answer');
		echo $this->Form->input('mark');
		echo $this->Form->input('instructions');
	?>
	</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
	<h3><?php __('Actions'); ?></h3>
	<ul>

		<li><?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $this->Form->value('Question.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $this->Form->value('Question.id'))); ?></li>
		<li><?php echo $this->Html->link(__('List Questions', true), array('action' => 'index'));?></li>
		<li><?php echo $this->Html->link(__('List Parts', true), array('controller' => 'parts', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Part', true), array('controller' => 'parts', 'action' => 'add')); ?> </li>
		<li><?php echo $this->Html->link(__('List Answers', true), array('controller' => 'answers', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Answer', true), array('controller' => 'answers', 'action' => 'add')); ?> </li>
	</ul>
</div>



<script type="text/javascript">
 
$(document).ready(function(){
 
    
 
    $("#addButton").click(function () {
 
	if(counter>20){
            alert("Only 10 textboxes allow");
            return false;
	}    
	$('<div id="tb'+counter+'"><span>Option '+counter+'</span><input type="text" id="QuestionOptions_'+counter+'" name="data[Question][options][]"></div>').appendTo("#TextBoxesGroup");
 
 
	counter++;
     });
 
     $("#removeButton").click(function () {
	if(counter==1){
          alert("No more textbox to remove");
          return false;
       }   
 
	counter--;
 
        $("#tb" + counter).remove();
 
     });
 
     
  });
</script>
